<template>
	<view class="settle">
		<view class="selectfull">
			<label class="radio" @click="getChecked">
				<radio :checked="isCheckAll" /><text>全选</text>
			</label>
		</view>
		<view class="total">
			合计：￥0.00
		</view>
		<button @click="getPay">结算{{checkAmount}}</button>
	</view>
</template>
<script>
	import {
		mapGetters,
		mapState
	} from "vuex"
	export default {
		data() {
			return {
				allChecked: '',
				secend: 3
			}
		},
		computed: {
			...mapGetters('cart', ['checkAmount', 'total']),
			...mapState('cart', ['cartList']),
			...mapState('user', ['token']),
			isCheckAll() {
				return this.checkAmount == this.total
			}
		},
		methods: {
			getChecked() {
				let type = this.isCheckAll
				type = type ? false : true
				this.$store.commit('cart/getCartState', type)
			},
			getPay() {
				if (this.checkAmount <= 0) return uni.$showMsg('请选择商品')
				if (!this.token) {
					let timer = setInterval(() => {
						uni.showToast({
							icon: 'none',
							title: `请登录后在结算，将在${this.secend--}秒后跳转到登录界面`,
							mask: true
						})
						if (this.secend < 0) {
							clearInterval(timer)
							uni.switchTab({
								url: '/pages/my/my'
							})
							return this.secend = 3
						}
					}, 1000)
				}
				this.goPay()
			},
			async goPay() {
				const orderInfo = {
					order_price: 0.01,
					consignee_addr: '重庆市',
					goods: this.cartList.filter(item => item.goods_state).map(item => ({
						goods_id: item.goods_id,
						goods_number: item.goods_count,
						goods_price: item.goods_price
					}))
				}
				let {data} =await uni.$http.post('/api/public/v1/my/orders/create',orderInfo)
				console.log(data);
			}
		}
	}
</script>
<style lang="scss">
	.settle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: bisque;
		position: sticky;
		bottom: 0;

		button {
			margin: 0;
		}
	}
</style>